package com.linzm.knowledge;

import org.junit.jupiter.api.Test;

/**
 * @Author zimingl
 * @Date 2023/1/15 13:02
 * @Description: TODO
 */
public class Sort {

    @Test
    public void test() {
//        int[] nums = new int[] {4,5,1,8,9,13,0,-1};
        int[] nums = new int[]{1, 2, 3};
        for (int i = 0; i < nums.length - 1; i++) {
            boolean flag = true;
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (nums[j] > nums[j + 1]) {
                    swap(nums, j, j + 1);
                    flag = false;
                }
            }
            if (flag) {
                break;
            }
        }
        int length = nums.length;
    }

    @Test
    public void test2() {
        int num = -2 % 2;
        int[] nums = new int[] {4,5,1,8,9,13,0,-1};
//        int[] nums = new int[]{1, 2, 3};
        for (int i = 0; i < nums.length - 1; i++) {
            boolean flag = true;
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] > nums[j]) {
                    swap(nums, i, j);
                    flag = false;
                }
            }
            if (flag) {
                break;
            }
        }
        int length = nums.length;
    }

    private void swap(int[] arr, int index1, int index2) {
        int tmp = arr[index1];
        arr[index1] = arr[index2];
        arr[index2] = tmp;
    }
}
